<template>
  <div class="personal">
    <router-link :to="'/edit_profile/' + userinfo.id">
      <div class="profile">
        <!-- $axios.defaults.baseURL读取axios的服务器路径 -->
        <img :src="userinfo.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span class="iconfont iconxingbienan"></span>{{ userinfo.nickname }}
          </div>
          <div class="time">{{ userinfo.create_date | dataForm }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <mycell title="我的关注" desc="关注的用户" />
    <mycell title="我的跟帖" desc="跟帖/回复" />
    <mycell title="我的收藏" desc="文章/视频" />
    <mycell title="设置" />
    <mybutton>登录</mybutton>
  </div>
</template>

<script>
// 引入封装的单元格
import mycell from "@/components/mycell.vue";
// 引入按钮的封装
import mybutton from "@/components/mybutton.vue";
// 引入封装的axios 请求
import { getUser } from "@/apis/user.js";
// 引入基准路劲
import axios from "@/utils/myaxios.js";
// 引入过滤器
import { dataForm } from "@/utils/myfilter.js";

export default {
  data() {
    return {
      userinfo: {},
    };
  },
  components: {
    mycell,
    mybutton,
  },
  filters: {
    dataForm,
  },
  // 页面一加载就返送axios 请求 使用钩子函数 mounted
  async mounted() {
    let id = this.$route.params.id;
    let res = await getUser(id);
    // console.log(res);
    this.userinfo = res.data.data;
    console.log(this.userinfo);
    // 判定图片是否有 要是没有就默认给一张
    if (this.userinfo.head_img) {
      // 如果有就拼接基准路径
      this.userinfo.head_img = axios.defaults.baseURL + this.userinfo.head_img;
    } else {
      // 如果没有就给一张默认的图片
      this.userinfo.head_img =
        axios.defaults.baseURL + "/uploads/image/pages.png";
    }
  },
};
</script>

<style lang='less' scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}

.btn {
  margin: 20px auto;
  background-color: #f00;
}
</style>